package com.linkstec.quartz.source;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;


/**
 * @Description: 测试类
 * 
 * @ClassName: QuartzTest.java
 */
public class QuartzTest {
    @Test
    public void quartz() {
        try {
            SchedulerFactory gSchedulerFactory = new StdSchedulerFactory();
            Scheduler sche = gSchedulerFactory.getScheduler();
            String job_name = "动态任务调度";
            System.out.println("【系统启动】开始(每1秒输出一次)...");
            Map<String, Object> map = new HashMap<String, Object>();
            MonitorRuleDto monitorRuleDto = new MonitorRuleDto();
            monitorRuleDto.setMonitorName("测试参数1");
			map.put("monitorRule", monitorRuleDto);
            QuartzManager.addJob(sche, job_name, QuartzJobExample.class, "0/1 * * * * ?", map);
//            QuartzManager.addJob(sche, "动态任务调度2", QuartzJobExample.class, "0/1 * * * * ?", map);

            Thread.sleep(3000);
            System.out.println("【修改时间】开始(每2秒输出一次)...");
            Map<String, Object> map2 = new HashMap<String, Object>();
            monitorRuleDto.setMonitorName("测试参数2");
            map2.put("monitorRule", monitorRuleDto);
            System.out.println(map2.get("monitorRule"));
            QuartzManager.modifyJobTime(sche, job_name, "10/2 * * * * ?", map2);
            Thread.sleep(4000);
            System.out.println("【移除定时】开始...");
            QuartzManager.removeJob(sche, job_name);
            System.out.println("【移除定时】成功");

            System.out.println("【再次添加定时任务】开始(每10秒输出一次)...");
            QuartzManager.addJob(sche, job_name, QuartzJobExample.class, "*/10 * * * * ?", map);
            Thread.sleep(30000);
            System.out.println("【移除定时】开始...");
            QuartzManager.removeJob(sche, job_name);
            System.out.println("【移除定时】成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}